home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 364_01 / glob_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-24  |  27KB  |  1,023 lines

  1. /*
  2. HEADER:         ;
  3. TITLE:          C-ACROSS;
  4. VERSION         1.02
  5.  
  6. DESCRIPTION:   "Utility for multiple module programs. Produces
  7.       Six indexes of functions, prototypes, and globals that
  8.       enable user to 'see across' modules for use in checking
  9.       and comparison.  One of these is type of hierarchical
  10.       functions list, a listing by module of functions
  11.       and calls made FROM them; another is alphabetical list
  12.       of functions and calls made TO them. Globals listed
  13.       in schematic descriptors which record all modifiers
  14.       and qualifiers and enable checking of declarators
  15.       across modules. Creates, on request, header file
  16.       consisting of prototypes constructed from function
  17.       definitions. Can list user types #defined and some
  18.       preprocessor #defines. Full documentation in README.CA";
  19.  
  20. KEYWORDS:       Utility, Cross Reference, Deubgging;
  21. SYSTEM:         MS-DOS;
  22. FILENAME:       GLOB_CA.C;
  23.  
  24. WARNINGS:      "1. Assumes function definitions conform with
  25.         ANSI standards and have prototype form. See
  26.         also "Caveats and Restrictions" in README.CA.
  27.         2. Assumes syntactically correct source files.
  28.         3. Written and tested using Microsoft QuickC.
  29.         4. Copyright retained.  See Copyright
  30.         information in README.CA.";
  31.  
  32. SEE-ALSO:      EXIT_CA.C, GLOB_CA.C, FUNC_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
  34.            UTLG_CA.C, XRF_CA.C, README.CA,
  35.            CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
  36. AUTHORS:       Myron Turner;
  37. COMPILERS:     Microsoft C;
  38.  
  39. */
  40.  
  41.  
  42. /***************************  C-ACROSS  ***************************
  43.                    V. 1.02
  44.                Copyright (C) Myron Turner
  45.  
  46.               333 Bartlet Ave.
  47.               Winnipeg, Manitoba
  48.               Canada R3L 0Z9
  49.               (204) 284-8387
  50.  
  51. ********************************************************************/
  52.  
  53. /*lint -esym(534,storage_class,process_vars)  */
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include <malloc.h>
  57. #include <ctype.h>
  58.  
  59. #define EXTERNAL
  60. #define INCLUDEFILES_DEFINE
  61. #define TYPEDEF_DEFINE
  62. #define TDEF_EXTERNAL
  63. #include "ca.h"
  64. #include "ca_decl.h"
  65. #include "keywords.h"
  66.  
  67. static void glob_ca_msgs(int Line, char * Mod, struct func *func_top );
  68. /* externs */
  69. extern struct includeFILE inclF;
  70. extern struct func  *FirstFunction;
  71. extern int function_no;
  72. extern int reading_includeF;
  73. extern int __mods[_MAX_MODS];
  74. extern FILE *scrn_out;
  75. extern int IfDefOFF;
  76. extern char *CurrentMod;
  77. /* globals */
  78. struct globals_list *global = NULL, *globals_start = NULL;
  79. char STRUNbuf[32];
  80.  
  81. #define SEMI_COLON (int) ';'
  82. #define OPEN_PAREN (int) '('
  83. #define CLOSE_PAREN (int) ')'
  84. #define CLOSE_BRACKET (int) '}'
  85. #define OPEN_BRACKET  '{'
  86. #define PROTOTYPE OPEN_PAREN
  87. #define COMPLEX_DECL CLOSE_PAREN
  88.  
  89. #define inSTRUCTUNION -1
  90. #define TYPEDEF_OPEN TYPEDEF + 101
  91. #define INCLUDEFILE 1
  92.  
  93. #define COMPLEX_INI  -1
  94.  
  95.  
  96. #define conv_sign_type(s,t) {   s = (char)((t & 0xFF00) >> 8); \
  97.                 t = (t & 0x00FF);   }
  98. #define is_outsideFunction(n) ((n <  func_top->line_no) \
  99.                 || (n > func_top->endfunc_line ))
  100.  
  101. static char COMPLEXdeclbuf[60];
  102. static int  COMPLExp = COMPLEX_INI;
  103. static int in_structunion = 0;
  104. static struct func * FN_ALPHAtop;
  105. extern int In_MainLoop;
  106. extern FILE **FP_ADDRESS;
  107. extern unsigned int inclfLine;
  108. extern unsigned int inclFini;
  109.  
  110. #define DEBUG_LINE 20
  111. struct func * record_variables(FILE *fp, FILE *rptfp,
  112.             struct func *start, struct func **func_alphatop)
  113. {
  114.   char  storage, *p,  *end_statement, buffer[261];
  115.   static struct func *func_top = NULL;
  116.   static struct func *previous = NULL;
  117.  
  118.   unsigned line_num = 0, lineno;
  119.   int inquotes = 0, intypedf = 0, t_pos = 0, delim = 0;
  120.   int preproc_type, skip_ifdef = 0;
  121.   int next_statement = 0, split_line = 0,  __type = NO_TYPE;
  122.   FILE * hold_fp  = fp;
  123.   char *in_comment = NULL;
  124.  
  125.   FP_ADDRESS = &fp;
  126.   rewind(fp);   In_MainLoop = 0;
  127.   FN_ALPHAtop = NULL;
  128.  
  129.   if(!func_top) func_top = FirstFunction;
  130.     else func_top = start->next_function;
  131.  
  132.   if(func_top && func_top->fnptr) func_top =  skip_fnptrs(func_top);
  133.  
  134.   glob_ca_msgs( __LINE__, __FILE__, func_top );
  135.  
  136.   ini_if_def_stack();
  137.  
  138. start_GlobalsLoop:
  139.  
  140.   while (  fgets (buffer, 160, fp) )
  141.     {
  142.  
  143.  
  144.     if (!reading_includeF)  lineno = ++line_num;
  145.         else lineno = ++inclfLine;
  146.  
  147.     p = buffer;
  148.     if(line_num == DEBUG_LINE)
  149.         line_num  = DEBUG_LINE;
  150.  
  151.      if (in_comment) {
  152.          in_comment = is_closed_comment(p);
  153.          if (in_comment == (char *) scrn_out) {
  154.         in_comment = comment_error(func_top, lineno, p);
  155.              }
  156.          }
  157.          else in_comment = is_comment(p);
  158.  
  159.   if(func_top)
  160.   {
  161.     if (is_outsideFunction(line_num) )
  162.     {
  163.  
  164.      next_statement = is_nextstatement(&p);  /* if not blank line */
  165.  
  166.      while (next_statement)
  167.       {
  168.  
  169.  
  170.        do {
  171.          if ( (inquotes = isliteral(p)) ) p++;
  172.          if (*p == '\n') { next_statement = 0; break; }
  173.        } while (inquotes );
  174.        while (iswhite(*p)) p++;
  175.  
  176.        if ( (preproc_type = is_includeF(p, hold_fp)) == INCLUDEFILE)
  177.                                 break;
  178.        if (preproc_type ==  PREPROCESSOR)
  179.            if (!IfDefOFF) skip_ifdef = is_else_if(p, skip_ifdef);
  180.        if (skip_ifdef) { next_statement = 0; break; }
  181.  
  182.         COMPLExp = COMPLEX_INI;
  183.         if( !(delim == PROTOTYPE  || split_line) )
  184.         if (!intypedf && !isdelim(*p) )
  185.           if (in_structunion || (t_pos = data_type_(p, &__type) )) {
  186.  
  187.         if (__type != NO_TYPE ) {
  188.             char *complex_p = p;
  189.             if(!intypedf && !in_structunion) complex_p += t_pos;
  190.             delim = is_prototype(p);
  191.             if ( (delim != PROTOTYPE) ||
  192.             (delim == PROTOTYPE &&
  193.             (COMPLExp = is_complex_decl(complex_p))) ) {
  194.                t_pos = sign_or_ld(p, t_pos, &__type);
  195.                process_vars(p, t_pos, func_top, __type, lineno,
  196.                             storage=0,  rptfp);
  197.               }
  198.  
  199.             }
  200.         }
  201.         else if (__type == TYPEDEF_OPEN) intypedf = 1;
  202.  
  203.         if(!t_pos && __type != PREPROCESSOR) {
  204.           if (!intypedf && !in_structunion) {
  205.           if (!vol_const(p, func_top, lineno, &__type, rptfp))
  206.          delim = storage_class(p, func_top, lineno, &__type, rptfp);
  207.            }
  208.         }
  209.        if (next_statement)
  210.         {
  211.          next_statement = 0;
  212.          end_statement = strchr(p, SEMI_COLON);
  213.          if (end_statement || __type == PREPROCESSOR) {
  214.         intypedf = 0;
  215.         delim = 0;
  216.         split_line = 0;
  217.         if (end_statement)  {
  218.            p = end_statement + 1;
  219.            next_statement = is_nextstatement(&p);
  220.            }
  221.         }
  222.         else
  223.         if (!intypedf && !in_structunion)
  224.             split_line = 1;
  225.  
  226.         }
  227.  
  228.  
  229.       }                  /* while (next_statement) */
  230.  
  231.     }                    /* if (is_outsideFunction(line_num)) */
  232.      else
  233.      storage_class(p, func_top, lineno,  &__type, rptfp);
  234.  
  235.  
  236.     if (line_num >= func_top->endfunc_line) {
  237.        previous = func_top;
  238.        func_top = func_top->next_function;
  239.        }
  240.  
  241.   }   /* if (func_top) */
  242.  
  243.     }     /* while (fgets. . .) */
  244.  
  245.     next_statement = 0;
  246.     end_statement = NULL;
  247.     intypedf = 0;
  248.     delim = 0;
  249.     split_line = 0;
  250.  
  251.   if (close_include(hold_fp, &fp, rptfp, CurrentMod))
  252.             goto start_GlobalsLoop;
  253.  
  254.   free_if_def_stack();
  255.   func_top = previous;
  256.   if (FN_ALPHAtop) *func_alphatop = FN_ALPHAtop;
  257.   return(previous);
  258.  
  259. }
  260.  
  261.  
  262. static int xt_struct_union(char *p, int __type)
  263. {
  264.   char *ptr = NULL;
  265.   char *initializing = NULL;
  266.   static char *close_brackets = NULL;
  267.   static char *open_brackets = NULL;
  268.   static char *ending_semicol = NULL;
  269.   static int identified = 0;
  270.   size_t count;
  271.  
  272.       if (ending_semicol) {
  273.       in_structunion = 0;
  274.       open_brackets = NULL;
  275.       close_brackets = NULL;
  276.       ending_semicol = NULL;
  277.       }
  278.  
  279.       initializing = strchr(p, '=');
  280.       if (initializing) {
  281.      *initializing = ';';
  282.      *(++initializing) = '\0';
  283.      }
  284.  
  285.       if(!open_brackets) {
  286.      open_brackets = strchr(p, (int) OPEN_BRACKET);
  287.      if(open_brackets) in_structunion = 1;
  288.      }
  289.  
  290.        if (open_brackets && !close_brackets)
  291.      close_brackets = strchr(p, CLOSE_BRACKET);
  292.  
  293.        if (close_brackets && !ending_semicol) {
  294.       ending_semicol = strchr(p, SEMI_COLON);
  295.       }
  296.  
  297.  
  298.        if (in_structunion && !close_brackets)  {
  299.       if (!identified) { isolate_strun(p, __type); identifie